Skip to content

Add Grin wallet core integration - #1538

Open
sneurlax wants to merge 2 commits into
stagingfrom
feat/grin
Open

sneurlax wants to merge 2 commits into
stagingfrom
feat/grin

Conversation

@sneurlax

@sneurlax sneurlax commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Add Grin and tGrin coin definitions, wallet registration, backup and restore, node handling (including onion nodes over Tor), scan and rescan, lifecycle, deletion, transaction mapping, and the native library check.
  • Implement the wallet core and its transport policy through the public grin_native package only.
  • Add unit coverage for wallet state, invoices, transport, scanning, errors, transaction mapping, and the wallets service.

Grin is not added to the app's coin list here. The Slatepack screens it needs come with #1540, along with the coin list entry, the README line and the wallet creation matrix entry.

Commits

  1. style: dart format five views that predate the 3.13 SDK bump is formatter output only. Those five files were last changed before the SDK constraint moved to 3.13, so CI's format check fails on any change to them. Running dart format on the staging versions reproduces this commit.
  2. feat: add Grin wallet through grin_native is the change.

Size

The feature commit is 67 files, +8689/-74. New Grin library files are about 3.4k lines, including about 180 lines of checkpoint data, and new tests and fakes about 4.5k. Existing files get +560/-69 in lib/ and +238/-1 in tests, mostly adding Grin to existing coin checks: restore flows, the node form, wallet settings, send fee handling, the native library list, the price id, and the reset list. The larger shared edits are the Grin delete, deferred-delete retry and unfinished-wallet secret cleanup in services/wallets.dart, Grin status labels and keys in TransactionV2, onion handling in the node form, the Stack Backup wait for the Grin scan, its choice of wallet ids and the Grin files its revert deletes, and a test-only coin list override in AppConfig.

Since the last push

Fixes for the fifth review, of a94a821c2. Each has a test that fails without it. The fixes for the consolidated review of 20cf703b0 and for my own review were in the previous push.

  • Cancelling a Stack Backup restore while a Grin wallet scanned left "Cancelling restore. Please wait." up until the scan reached the tip, and the finished scan was then reverted. A cancel now ends the wait for the scan, so the revert follows at once.
  • After a cancelled restore, restoring the same backup marked its Grin wallet as failed: the revert removed the wallet record but left the Grin directory and password, and the next restore reuses the id. The revert now deletes both for each Grin wallet it removes; a busy directory is deleted at the next start.
  • A node address with a character a host name cannot have, such as exa mple.com, was accepted because Uri.parse percent-encodes it, and the wallet then failed to open with it. grinNodeUrl now refuses such a host, so the form shows why and a saved node gets the invalid-node handling.
  • Clearing an onion host with the field's X button left the earlier settings pending, so the first character typed afterwards overwrote the network option picked meanwhile. The X button now puts back the earlier settings, as typing the host away does.

Not changed here

  • At startup, if one wallet's init() throws, services/wallets.dart skips the startup refresh for every wallet. This predates this PR and affects all coins; Grin is one more coin whose init() can throw.
  • Grin's defaultBlockExplorer throws, as Epic Cash's and MWC's do. Hide unsupported coins from block explorer settings #1518 leaves those coins out of the block explorer settings and should land before Integrate Grin with the shared Slatepack UI #1540, which lists Grin.
  • WalletInfo.updateOtherData reads the record and writes it back outside one transaction, so writes from different parts of the app can overwrite each other. That is staging's helper, used by every coin.
  • The node form reports a Grin node that the Tor settings block as a failed test and logs the reason, as the shared node test does for every coin.
  • A deferred Grin delete that keeps failing is tried again at every start. Dropping it would leave the wallet files on disk.
  • An HTTP send without Tor needs the acknowledgements that Integrate Grin with the shared Slatepack UI #1540's confirmation screen collects. With this PR alone it is refused at confirmation.
  • A reverted Stack Backup restore leaves the recovery phrases and other secrets of the wallets it removes in secure storage, for every coin. That predates this PR; the Grin password and files are now deleted.
  • A restore killed between creating its wallet record and starting can still open as a new wallet. The window is the few calls between Wallet.create and init(isRestore: true).

Dependency boundary

grin_native resolves from https://github.com/cypherstack/grin_native at 001df2a47375dc03b7d5a8024b53d96f458cccaf, path packages/grin_native. Its build hook compiles grin-ffi against https://github.com/cypherstack/grin-wallet at 59537fb, whose grin submodule is https://github.com/cypherstack/grin at 99f327d, all over public HTTPS. There is no bare grin dependency or package:grin/ import. The Epic and MWC plugin pins are staging's.

grin_native is outside ENABLE_GRIN in the pubspec template because lib/ uses the API it re-exports directly. The GRIN flag selects the native backend and decides whether the hook builds grin-ffi at all.

Verification

At this PR's head (07b96f261):

  • dart analyze (lib, test, integration_test): no errors, and no new issues in the changed files.
  • CI's format check on the PR's changed Dart files: clean.
  • The Grin wallet tests, with the backup id and owner-only directory tests: 154 pass, with Grin in the app config's coin list and with it taken out, as in CI here. The node form tests pass as well.
  • The full flutter test suite: 1606 passed, 8 skipped, and two Firo cache reset tests in firo_cache_refresh_reset_test.dart that time out in full runs on this machine and pass when run on their own, as in earlier review stacks.
  • The eight scripts/tests that CI runs, run as CI runs them: pass.
  • grin_native 001df2a: dart run tool/ci.dart passes, with the Android and Flutter build stages skipped; that includes cargo test, the bindings check and both packages' Dart tests.
  • Each new test was checked against the code without its fix, and fails there.

At the top of the stack (#1540), the full suite: 1735 passed, 8 skipped, and one Firo cache reset test in firo_cache_reset_lifecycle_test.dart that timed out and passes on its own. The native e2e suite from #1539: 9/9, with grin-ffi built from grin_native 001df2a.

@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.93868% with 442 lines in your changes missing coverage. Please review.
✅ Project coverage is 21.57%. Comparing base (dcd2d9a) to head (07b96f2).
⚠️ Report is 11 commits behind head on staging.

Files with missing lines Patch % Lines
lib/wallets/wallet/impl/grin_wallet.dart 86.90% 116 Missing ⚠️
...rk_settings_view/wallet_network_settings_view.dart 2.04% 96 Missing ⚠️
...iew/restore_options_view/restore_options_view.dart 0.00% 59 Missing ⚠️
...wallet_view/sub_widgets/wallet_options_button.dart 0.00% 29 Missing ⚠️
lib/utilities/test_grin_node_connection.dart 0.00% 25 Missing ⚠️
...ackup_views/sub_widgets/restoring_wallet_card.dart 0.00% 24 Missing ⚠️
...settings/wallet_settings_wallet_settings_view.dart 0.00% 21 Missing ⚠️
...ck_backup_views/helpers/restore_create_backup.dart 51.35% 18 Missing ⚠️
...wallets/wallet/supporting/grin/grin_transport.dart 73.21% 15 Missing ⚠️
lib/services/wallets.dart 74.19% 8 Missing ⚠️
... and 13 more
Additional details and impacted files
@@             Coverage Diff             @@
##           staging    #1538      +/-   ##
===========================================
+ Coverage    20.67%   21.57%   +0.90%     
===========================================
  Files         1148     1159      +11     
  Lines       114416   115925    +1509     
===========================================
+ Hits         23653    25015    +1362     
- Misses       90763    90910     +147     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sneurlax
sneurlax changed the base branch from staging to feat/slatepack-interface November 20, 2026 08:59
@sneurlax
sneurlax force-pushed the feat/grin branch 5 times, most recently from d1fa13d to 0262879 Compare November 21, 2026 09:20
Base automatically changed from feat/slatepack-interface to staging December 2, 2026 15:02
@sneurlax
sneurlax marked this pull request as ready for review December 2, 2026 15:06
@sneurlax
sneurlax added this pull request to stack #1556 December 2, 2026 17:24
@sneurlax
sneurlax force-pushed the feat/grin branch 2 times, most recently from 5133ab4 to 8610907 Compare December 2, 2026 20:22
These files were last changed before the SDK constraint moved to 3.13, so
CI's format check would fail on any later change to them. This commit is
the formatter's output only.
@sneurlax
sneurlax force-pushed the feat/grin branch 3 times, most recently from 9596ad5 to a94a821 Compare December 3, 2026 18:00
Add the Grin coin, wallet core and transport policy through grin_native,
the only Grin Dart dependency. grin_native 001df2a builds grin-ffi from
cypherstack/grin-wallet, whose grin submodule is cypherstack/grin.

Every app depends on grin_native for the API lib/ uses, but only an app
configured with GRIN builds and bundles grin-ffi. process_pubspec_deps.dart
sets hooks.user_defines.grin_native.enabled from the GRIN flag, so Stack
Duo and Campfire turn the hook off.

Grin is not in the app's coin list yet. A send to a grin1 address creates
a Slatepack that only the Slatepack screens can show, so the coin list
entry comes with them. Until then, tests that build a Grin wallet add Grin
to the coin list through AppConfig.coinsOverride, so they run in every app
config.

Grin tests reuse the MemorySecrets fixture from xelis_test_fakes.dart.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant